extends Control

@onready var score_label = $CenterContainer/VBoxContainer/HBoxContainer/ScoreLabel
@onready var newHSContainer = $CenterContainer/VBoxContainer/NewHighscoreContainer
@onready var noHSContainer = $CenterContainer/VBoxContainer/NoHighscoreContainer
@onready var highscore_label = $CenterContainer/VBoxContainer/NoHighscoreContainer/highscoreLabel

func _ready():
	var highscore = GameManager.get_highscore_entry(GameManager.last_level_path)
	newHSContainer.visible = false
	noHSContainer.visible = false
	score_label.text = str(GameManager.last_level_score)
	if (GameManager.last_level_score > highscore and GameManager.last_level_score > 0):
		newHSContainer.visible = true
		noHSContainer.visible = false
	elif GameManager.get_highscore_entry(GameManager.last_level_path) > 0:
		noHSContainer.visible = true
		highscore_label.text = str(highscore)
	GameManager.save_score()



func _on_retry_button_pressed():
	GameManager.load_level(GameManager.last_level_path)
	


func _on_level_selection_button_pressed():
	get_tree().paused = false
	get_tree().change_scene_to_file("res://src/UI/LevelSelectionScreen.tscn")


func _on_exit_button_pressed():
	get_tree().paused = false
	get_tree().change_scene_to_file("res://src/UI/MainMenuScreen.tscn")
